import Vue from 'vue'
import App from './App'
import router from './router'
import FastClick from "fastclick";
import "./styles/icon/icon.css"
import "./styles/reset.css"
import "./styles/style.css"
import 'lib-flexible'
import "./plugins/vant.js"
import store from "./store"
import utils from '@/utils/utils.js';
import md5 from 'js-md5';
import './utils/http.js'
import clipboard from 'clipboard';
import Header from './views/components/header.vue'


Vue.prototype.utils = utils;
Vue.prototype.back = function() {
    if (window.history.length <= 1) {
        router.push({ path: '/' })
        return false
    } else {
        router.back()
    }
}
Vue.prototype.$md5 = md5
Vue.component('Header', Header);


//注册到vue原型上
Vue.prototype.clipboard = clipboard;
FastClick.attach(document.body);

Vue.config.productionTip = false
FastClick.prototype.focus = function(targetElement) {

    var length;

    //兼容处理:在iOS7中，有一些元素（如date、datetime、month等）在setSelectionRange会出现TypeError

    //这是因为这些元素并没有selectionStart和selectionEnd的整型数字属性，所以一旦引用就会报错，因此排除这些属性才使用setSelectionRange方法

    if (getPhoneType() == 'ios' && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month' && targetElement.type !== 'email' && targetElement.type !== 'number') {

        length = targetElement.value.length;

        targetElement.setSelectionRange(length, length);

        /*修复bug ios 11.3不弹出键盘，这里加上聚焦代码，让其强制聚焦弹出键盘*/

        targetElement.focus();

    } else {

        targetElement.focus();

    }

};

// 判断当前机型是否为ios
function getPhoneType() {
    let ua = navigator.userAgent.toLowerCase()
    return ua.includes('iphone') ? 'ios' : 'android'
}

/* eslint-disable no-new */
// new Vue({
//   el: '#app',
//   router,
//   store,
//   components: { App },
//   template: '<App/>'
// })

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount("#app");